package com.neusoft.yuejian_01.model;
import com.neusoft.yuejian_01.base.BaseModel;
import com.neusoft.yuejian_01.javabean.CommentListBean;
import com.neusoft.yuejian_01.javabean.SetPictureBean;
import com.neusoft.yuejian_01.javabean.setCommentBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.service.SetPictureService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/10/9.
 */

public class SetPictureModel extends BaseModel {

    public void getSetPicturelist(final RetrofitListener listener) {
        this.flag = Const.SetPicturelist;
        SetPictureService setPictureService = retrofit.create( SetPictureService.class);
        Call<List<SetPictureBean>> call = setPictureService.getPostlist();
        Callback<List<SetPictureBean>> callback = new Callback<List<SetPictureBean>>() {
            @Override
            public void onResponse(Call<List<SetPictureBean>> call, Response<List<SetPictureBean>> response) {
                List<SetPictureBean> SetPicture = response.body();
                listener.onSuccess(SetPicture,flag);
            }
            @Override
            public void onFailure(Call<List<SetPictureBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    public void getDashiSetPicturelist(int c_id,final RetrofitListener listener) {
        this.flag = Const.DashiSetPicturelist;
        SetPictureService setPictureService = retrofit.create( SetPictureService.class);
        Call<List<SetPictureBean>> call = setPictureService.getDashiSetPicturelist(c_id);
        Callback<List<SetPictureBean>> callback = new Callback<List<SetPictureBean>>() {
            @Override
            public void onResponse(Call<List<SetPictureBean>> call, Response<List<SetPictureBean>> response) {
                List<SetPictureBean> SetPicture = response.body();
                listener.onSuccess(SetPicture,flag);
            }
            @Override
            public void onFailure(Call<List<SetPictureBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    public Call<List<SetPictureBean>> getmyCollectlist(int c_id){
        SetPictureService setPictureService = retrofit.create( SetPictureService.class);
        return setPictureService.getJulebuSetPicturelist(c_id);
    }
    public void getmyCollectlist(int c_id,final RetrofitListener listener) {
        this.flag = Const.MyCollectlist;
        SetPictureService setPictureService = retrofit.create( SetPictureService.class);
        Call<List<SetPictureBean>> call = setPictureService.getJulebuSetPicturelist(c_id);
        Callback<List<SetPictureBean>> callback = new Callback<List<SetPictureBean>>() {
            @Override
            public void onResponse(Call<List<SetPictureBean>> call, Response<List<SetPictureBean>> response) {
                List<SetPictureBean> SetPicture = response.body();
                listener.onSuccess(SetPicture,flag);
            }
            @Override
            public void onFailure(Call<List<SetPictureBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }



    public Call <SetPictureBean> getPostDetail(String p_id){
        SetPictureService setPictureService = retrofit.create( SetPictureService.class);
        return setPictureService.getPostDetail(p_id);
    }
    public void getMePostlist(int u_id,final RetrofitListener listener) {
        this.flag = Const.MePostList;
        SetPictureService setPictureService = retrofit.create( SetPictureService.class);
        Call<List<SetPictureBean>> call = setPictureService.getMePostlist(u_id);
        Callback<List<SetPictureBean>> callback = new Callback<List<SetPictureBean>>() {
            @Override
            public void onResponse(Call<List<SetPictureBean>> call, Response<List<SetPictureBean>> response) {
                List<SetPictureBean> SetPicture = response.body();
                listener.onSuccess(SetPicture,flag);
            }
            @Override
            public void onFailure(Call<List<SetPictureBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    public void getCommentlist(int p_id,final RetrofitListener listener) {
        this.flag = Const.CommentList;
        SetPictureService setPictureService = retrofit.create( SetPictureService.class);
        Call<List<CommentListBean>> call = setPictureService.getCommentlist(p_id);
        Callback<List<CommentListBean>> callback = new Callback<List<CommentListBean>>() {
            @Override
            public void onResponse(Call<List<CommentListBean>> call, Response<List<CommentListBean>> response) {
                List<CommentListBean> commentListBean = response.body();
                listener.onSuccess(commentListBean,flag);
            }
            @Override
            public void onFailure(Call<List<CommentListBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    public void addcomment(int u_id, int postId, String coinfo,final RetrofitListener listener) {
        this.flag = Const.AddComment;
        SetPictureService setPictureService = retrofit.create(SetPictureService.class);
        Call call = setPictureService.addcomment(u_id, postId, coinfo);
        call.enqueue(new Callback<setCommentBean>() {
            @Override
            public void onResponse(Call<setCommentBean> call, Response<setCommentBean> response) {
                setCommentBean setCommentBean=response.body();
                listener.onSuccess(setCommentBean,flag);
            }
            @Override
            public void onFailure(Call<setCommentBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }


}
